<!--
* description:S-维修工单查询总部
* author:shensai
* createdDate: 2021-2-23
-->
<template>
  <div>
    <div class="app-container app-container-table">
      <one-table-template
        ref="multipleTable"
        :dynamic-buttons="tableButtons"
        :dynamic-components="tableComponents"
        :dynamic-api-config="apiConfig"
        :dynamic-table-cols="tableCols"
        :dynamic-form-fields="formField"
        :dynamic-is-show-select="false"
        :dynamic-is-show-more-btn="false"
      />
    </div>
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { exportExcel } from '@/utils/getTimeString'
import { vehiclePdiPriceInquirys } from '@/api/se/vehiclePdiPriceInquiry'
import Vue from 'vue'
export default {
  name: 'MaintenanceHeadquarters',
  components: {
    OneTableTemplate
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      [to.path, 'supplierMessage-edit'],
      () => {
        next()
      }
    )
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      titleName: '',
      editRowData: {},
      editPopupsState: '',
      editPopupsVisible: false,
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.workOrderList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey0',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          name: 'search', // 按钮图标样式
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey1',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: '导出', // 查询
          name: 'export', // 按钮图标样式
          position: 'left',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 显示组件
            {
              compKey: 'compKey1',
              labelName: '到店日期：',
              codeField: 'repairTimeStart,repairTimeEnd',
              component: () =>
                import('@/components/org/datePicker/datePicker'),
              dateType: 'daterange',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '派工单号：',
              codeField: 'repairOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '车牌号：',
              codeField: 'carLicense',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: 'VIN码：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '送修人：',
              codeField: 'repairMan',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '送修人电话：',
              codeField: 'repairTel',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },

            {
              compKey: 'compKey7',
              labelName: '车主姓名：',
              codeField: 'custName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey8',
              labelName: '车主电话：',
              codeField: 'custTel',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            },
            {
              compKey: 'compKey9',
              labelName: '维修状态：',
              codeField: 'repairOrderStatus',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: vehiclePdiPriceInquirys.repairOrderStatus,
                selectType: '1'
              },
              oFields: 'LOOKUP_VALUE_CODE,LOOKUP_VALUE_NAME',
              type: 'dropdownList',
              isMust: false
            },
            {
              compKey: 'compKey10',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            }
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'controlBtn1',
              label: '操作',
              width: 80,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '查看',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: index => {
                    this.$router.push({
                      name: 'sysorderDetails',
                      params: {
                        updateControlId: this.$refs.multipleTable.list[index].updateControlId,
                        repairOrderCode: this.$refs.multipleTable.list[index].repairOrderCode,
                        dlrId: this.$refs.multipleTable.list[index].dlrId,
                        repairOrderId: this.$refs.multipleTable.list[index].repairOrderId,
                        repairOrderStatusName: this.$refs.multipleTable.list[index].repairOrderStatusName,
                        repairOrderStatus: this.$refs.multipleTable.list[index].repairOrderStatus
                      }
                    })
                  }
                }
              ]
            },
            {
              prop: 'dlrCode',
              label: '门店编码'
            },
            {
              prop: 'dlrFullName',
              label: '门店名称'
            },
            {
              prop: 'repairOrderCode',
              label: '派工单号'
            },
            {
              prop: 'repairOrderStatusName',
              label: '维修状态'
            },
            {
              prop: 'empName',
              label: '服务顾问'
            },
            {
              label: '创建时间',
              prop: 'createdDate',
              width: 100
            },
            {
              prop: 'carLicense',
              label: '车牌号'
            },
            {
              prop: 'custName',
              label: '车主姓名',
              width: 80
            },
            {
              prop: 'custTel',
              label: '车主电话'
            },
            {
              prop: 'repairTime',
              label: '到店时间'
            },
            {
              prop: 'preGetDate',
              label: '预计交车时间'
            },
            {
              prop: 'repairMan',
              label: '送修人',
              width: 80
            },
            {
              prop: 'repairTel',
              label: '送修人电话'
            },
            {
              prop: 'vin',
              label: 'VIN码'
            },
            {
              prop: 'deliveryDate',
              label: '销售交车日期'
            }
          ],
      formField: {
        repairTimeStart: '',
        repairTimeEnd: '',
        repairOrderCode: '',
        carLicense: '',
        vin: '',
        repairMan: '',
        repairTel: '',
        custName: '',
        custTel: '',
        repairOrderStatus: '',
        dlrCode: ''
      },
      // 是否使用刷新Key的方式刷新弹窗
      resetDialogKey: false
      // 单表格模版页面组件回调事件
    }
  },
  mounted() {
    this.queryTable(1)
  },
  methods: {
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.workOrderExcel.APIUrl,
        vehiclePdiPriceInquirys.workOrderExcel.ServiceCode,
        '维修工单查询总部'
      )
    }
  }
}
</script>
